﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace ZhangZhao.Web.H_UserAvatarComment
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int Id=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(Id);
				}
			}
		}
			
	private void ShowInfo(int Id)
	{
		ZhangZhao.BLL.H_UserAvatarComment bll=new ZhangZhao.BLL.H_UserAvatarComment();
		ZhangZhao.Model.H_UserAvatarComment model=bll.GetModel(Id);
		this.lblId.Text=model.Id.ToString();
		this.txtUserAvatarId.Text=model.UserAvatarId.ToString();
		this.txtCommentUserName.Text=model.CommentUserName;
		this.txtCommentBody.Text=model.CommentBody;
		this.txtCommentTime.Text=model.CommentTime.ToString();
		this.chkIsLike.Checked=model.IsLike;
		this.chkIsRecommend.Checked=model.IsRecommend;
		this.txtScore.Text=model.Score.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(!PageValidate.IsNumber(txtUserAvatarId.Text))
			{
				strErr+="UserAvatarId格式错误！\\n";	
			}
			if(this.txtCommentUserName.Text.Trim().Length==0)
			{
				strErr+="CommentUserName不能为空！\\n";	
			}
			if(this.txtCommentBody.Text.Trim().Length==0)
			{
				strErr+="CommentBody不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtCommentTime.Text))
			{
				strErr+="CommentTime格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtScore.Text))
			{
				strErr+="Score格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int Id=int.Parse(this.lblId.Text);
			int UserAvatarId=int.Parse(this.txtUserAvatarId.Text);
			string CommentUserName=this.txtCommentUserName.Text;
			string CommentBody=this.txtCommentBody.Text;
			DateTime CommentTime=DateTime.Parse(this.txtCommentTime.Text);
			bool IsLike=this.chkIsLike.Checked;
			bool IsRecommend=this.chkIsRecommend.Checked;
			int Score=int.Parse(this.txtScore.Text);


			ZhangZhao.Model.H_UserAvatarComment model=new ZhangZhao.Model.H_UserAvatarComment();
			model.Id=Id;
			model.UserAvatarId=UserAvatarId;
			model.CommentUserName=CommentUserName;
			model.CommentBody=CommentBody;
			model.CommentTime=CommentTime;
			model.IsLike=IsLike;
			model.IsRecommend=IsRecommend;
			model.Score=Score;

			ZhangZhao.BLL.H_UserAvatarComment bll=new ZhangZhao.BLL.H_UserAvatarComment();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
